package cn.south.campus.common.file.service;

import cn.south.campus.common.config.FileUploadConfig;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2025/3/28 9:55
 */
@Component
public class ImgJsonDeSerializer extends JsonDeserializer<String> {
    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String value = jsonParser.getValueAsString();
        if (value == null) {
            return null;
        }
        String[] split = value.split(",");
        StringBuilder sb = new StringBuilder();
        for (String s : split) {
            sb.append(s.replace(FileUploadConfig.DOMAIN, "")).append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }
}
